//
// Framework grid generation
// --------------------------------------------------

// Centered container element
@mixin gd-container-fixed($gutter: $grid-gutter-width) {
    margin-right: auto;
    margin-left: auto;
    padding-left: floor(($gutter / 2));
    padding-right: ceil(($gutter / 2));
    @include fn-clearfix;
}

// Creates a wrapper for a series of columns
@mixin gd-make-row($gutter: $grid-gutter-width) {
    margin-left: ceil(($gutter / -2));
    margin-right: floor(($gutter / -2));
    @include fn-clearfix;
}

// [converter] This is defined recursively in LESS, but Sass supports real loops
@mixin gd-make-grid-columns($i: 1, $list: ".col-xs-#{$i}") {
    @for $i from (1 + 1) through $grid-columns {
        $list: "#{$list}, .col-xs-#{$i}";
    }
    #{$list} {
        position: relative;
        padding-left: ceil(($grid-gutter-width / 2));
        padding-right: floor(($grid-gutter-width / 2));
        min-height: 1px;
    }
}

// [converter] This is defined recursively in LESS, but Sass supports real loops
@mixin gd-float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") {
    @for $i from (1 + 1) through $grid-columns {
        $list: "#{$list}, .col-#{$class}-#{$i}";
    }
    #{$list} {
        float: left;
    }
}

@mixin gd-calc-grid-column($index, $class, $type) {
    @if ($type == width) and ($index > 0) {
        .col-#{$class}-#{$index} {
            width: percentage(($index / $grid-columns));
        }
    }
    
    @if ($type == pull) and ($index > 0) {
        .col-#{$class}-pull-#{$index} {
            right: percentage(($index / $grid-columns));
        }
    }
    @if ($type == pull) and ($index == 0) {
        .col-#{$class}-pull-0 {
            right: auto;
        }
    }
    @if ($type == push) and ($index > 0) {
        .col-#{$class}-push-#{$index} {
            left: percentage(($index / $grid-columns));
        }
    }
    @if ($type == push) and ($index == 0) {
        .col-#{$class}-push-0 {
            left: auto;
        }
    }
    
    @if ($type == offset) {
        .col-#{$class}-offset-#{$index} {
            margin-left: percentage(($index / $grid-columns));
        }
    }
}

// [converter] This is defined recursively in LESS, but Sass supports real loops
@mixin gd-loop-grid-columns($columns, $class, $type) {
    @for $i from 0 through $columns {
        @include gd-calc-grid-column($i, $class, $type);
    }
}

// Create grid for specific class
@mixin gd-make-grid($class) {
    @include gd-float-grid-columns($class);
    @include gd-loop-grid-columns($grid-columns, $class, width);
    @include gd-loop-grid-columns($grid-columns, $class, pull);
    @include gd-loop-grid-columns($grid-columns, $class, push);
    @include gd-loop-grid-columns($grid-columns, $class, offset);
}
